shader
LGHexTile (

    float DiffuseAmt = .5,
    float SpecularAmt = .2,
    float Roughness = .1,
    color SpecularColor = 1,
    color TileColor = color(.55,0,0),
    color MortarColor = color(.5,.5,.5),
    float TileRadius = 0.08,
    float MortarWidth = 0.01,
    float TileVary = 0.15,
    float Scuffing = 0.5,
    float ScuffFrequency = 4,
    color ScuffColor = color (.05,.05,.05),
    float Stains = 0.4,
    float StainFrequency = 2,
    output color BSDF=0
)
{
    #define snoise(x) (2*noise(x)-1)
    #define snoise2(x,y) (2*noise((x),(y))-1)
    #define MINFILTERWIDTH 1.0e-7
    #define M_SQRT3 1.7320508 /* sqrt(3) */
       
    point Nf;
    color Ct, Ctile;
    float tilewidth;
    float ss, tt;
    float ttile, stile;
    float x, y;
    float mortar;
    float swidth, twidth, sfuzz, tfuzz, fuzzmax;
    float mw2, mw2srt3;
    float tileindex;
    float stain, scuff;
    float ks;

 	vector Vector = P;
 	Vector = vector(u,v,0);
    float s = Vector[0];
    float t = Vector[1];

    swidth = abs(Dx(s)) + abs(Dy(s));
    twidth = abs(Dx(t)) + abs(Dy(t));
    sfuzz = 0.5 * swidth;
    tfuzz = 0.5 * twidth;
    fuzzmax = max(sfuzz, tfuzz);
    Nf = N;

    tilewidth = TileRadius * M_SQRT3;
    tt = mod (t, 1.5*TileRadius);
    ttile = floor(t/(1.5*TileRadius));
    if (mod(ttile/2, 1) == 0.5)
       ss = s + tilewidth/2;
    else ss = s;
    stile = floor(ss / tilewidth);
    ss = mod(ss, tilewidth);
    mortar = 0;
    mw2 = MortarWidth/2;
    if (tt < TileRadius) {
      mortar =  1 - (smoothstep(mw2,mw2+sfuzz,ss) *
             (1 - smoothstep(tilewidth-mw2-sfuzz,tilewidth-mw2,ss)));
    }
    else {
      x = tilewidth/2 - abs(ss - tilewidth/2);
      y = M_SQRT3 * (tt - TileRadius);
      if (y > x) {
      if (mod (ttile/2, 1) == 0.5)
          stile -= 1;
      ttile += 1;
      if (ss > tilewidth/2)
          stile += 1;
    }

        mw2srt3 = M_SQRT3*mw2;
        mortar = (smoothstep(x-mw2srt3-tfuzz, x-mw2srt3, y) *
            (1 - smoothstep(x+mw2srt3, x+mw2srt3+tfuzz, y)));
    }

    tileindex = stile+41*ttile;
    Ctile = TileColor * (1 + TileVary * snoise(tileindex+0.5));

    stain = Stains * smoothstep (.5,1, noise(s*StainFrequency,t*StainFrequency));

    scuff = Scuffing * smoothstep (.6,1, noise(t*ScuffFrequency-90.26,s*ScuffFrequency+123.82));

    ks = SpecularAmt * (1-scuff/2);
    Ct = (1-stain) * mix(mix(Ctile, ScuffColor, scuff), MortarColor, mortar);

    Nf = normalize(N);
    BSDF = Ct;
   
}